/*
 * PresupuestoEstimado.java
 *
 * Created on 28-abril-2009 
 */
package investigaciones_itm.Presupuestos;

import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Body;
import com.sun.webui.jsf.component.Button;
import com.sun.webui.jsf.component.Form;
import com.sun.webui.jsf.component.Head;
import com.sun.webui.jsf.component.HiddenField;
import com.sun.webui.jsf.component.Html;
import com.sun.webui.jsf.component.Link;
import com.sun.webui.jsf.component.Page;
import com.sun.webui.jsf.component.PanelLayout;
import com.sun.webui.jsf.component.StaticText;
import com.sun.webui.jsf.component.Tab;
import com.sun.webui.jsf.component.TabSet;
import com.sun.webui.jsf.component.Table;
import com.sun.webui.jsf.component.TableColumn;
import com.sun.webui.jsf.component.TableRowGroup;
import com.sun.webui.jsf.component.TextField;
import com.sun.webui.jsf.model.DefaultOptionsList;
import com.sun.webui.jsf.model.DefaultTableDataProvider;
import javax.faces.FacesException;
import investigaciones_itm.RequestBean1;
import investigaciones_itm.ApplicationBean1;
import investigaciones_itm.SessionBean1;
import itm.bo.presupuestos.PresupuestosBO;
import itm.exception.ControlException;
import itm.vo.presupuestos.fuenteRubroVO;
import itm.vo.presupuestos.periodoRubroVO;
import itm.vo.presupuestos.presupuestosVO;
import itm.vo.presupuestos.rubroProyectoVO;
import itm.vo.proyectosInvestigacion.ProyectoInvestigacionVO;
import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlCommandButton;
import javax.faces.component.html.HtmlMessages;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.component.html.HtmlSelectOneListbox;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.component.UIParameter;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @author Administrador
 */
public class PresupuestoEstimado extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    private Page page1 = new Page();

    public Page getPage1() {
        return page1;
    }

    public void setPage1(Page p) {
        this.page1 = p;
    }
    private Html html1 = new Html();

    public Html getHtml1() {
        return html1;
    }

    public void setHtml1(Html h) {
        this.html1 = h;
    }
    private Head head1 = new Head();

    public Head getHead1() {
        return head1;
    }

    public void setHead1(Head h) {
        this.head1 = h;
    }
    private Link link1 = new Link();

    public Link getLink1() {
        return link1;
    }

    public void setLink1(Link l) {
        this.link1 = l;
    }
    private Body body1 = new Body();

    public Body getBody1() {
        return body1;
    }

    public void setBody1(Body b) {
        this.body1 = b;
    }
    private Form form1 = new Form();

    public Form getForm1() {
        return form1;
    }

    public void setForm1(Form f) {
        this.form1 = f;
    }
    private HtmlPanelGrid p3 = new HtmlPanelGrid();

    public HtmlPanelGrid getP3() {
        return p3;
    }

    public void setP3(HtmlPanelGrid hpg) {
        this.p3 = hpg;
    }
    private HtmlPanelGrid p4 = new HtmlPanelGrid();

    public HtmlPanelGrid getP4() {
        return p4;
    }

    public void setP4(HtmlPanelGrid hpg) {
        this.p4 = hpg;
    }
    private HtmlPanelGrid p5 = new HtmlPanelGrid();

    public HtmlPanelGrid getP5() {
        return p5;
    }

    public void setP5(HtmlPanelGrid hpg) {
        this.p5 = hpg;
    }
    private HtmlPanelGrid p6 = new HtmlPanelGrid();

    public HtmlPanelGrid getP6() {
        return p6;
    }

    public void setP6(HtmlPanelGrid hpg) {
        this.p6 = hpg;
    }
    private HtmlPanelGrid p7 = new HtmlPanelGrid();

    public HtmlPanelGrid getP7() {
        return p7;
    }

    public void setP7(HtmlPanelGrid hpg) {
        this.p7 = hpg;
    }
    private HtmlPanelGrid p8 = new HtmlPanelGrid();

    public HtmlPanelGrid getP8() {
        return p8;
    }

    public void setP8(HtmlPanelGrid hpg) {
        this.p8 = hpg;
    }
    private HtmlPanelGrid p9 = new HtmlPanelGrid();

    public HtmlPanelGrid getP9() {
        return p9;
    }

    public void setP9(HtmlPanelGrid hpg) {
        this.p9 = hpg;
    }
    private HtmlPanelGrid p10 = new HtmlPanelGrid();

    public HtmlPanelGrid getP10() {
        return p10;
    }

    public void setP10(HtmlPanelGrid hpg) {
        this.p10 = hpg;
    }
    private UISelectItems listbox1SelectItems = new UISelectItems();

    public UISelectItems getListbox1SelectItems() {
        return listbox1SelectItems;
    }

    public void setListbox1SelectItems(UISelectItems uisi) {
        this.listbox1SelectItems = uisi;
    }
    private UISelectItems listbox2SelectItems = new UISelectItems();

    public UISelectItems getListbox2SelectItems() {
        return listbox2SelectItems;
    }

    public void setListbox2SelectItems(UISelectItems uisi) {
        this.listbox2SelectItems = uisi;
    }
    private HtmlPanelGrid gridPanel1 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel1() {
        return gridPanel1;
    }

    public void setGridPanel1(HtmlPanelGrid hpg) {
        this.gridPanel1 = hpg;
    }
    private TabSet tabSet1 = new TabSet();

    public TabSet getTabSet1() {
        return tabSet1;
    }

    public void setTabSet1(TabSet ts) {
        this.tabSet1 = ts;
    }
    private Tab tabEstPresupuesto = new Tab();

    public Tab getTabEstPresupuesto() {
        return tabEstPresupuesto;
    }

    public void setTabEstPresupuesto(Tab t) {
        this.tabEstPresupuesto = t;
    }
    private PanelLayout panelRubroXFuente = new PanelLayout();

    public PanelLayout getPanelRubroXFuente() {
        return panelRubroXFuente;
    }

    public void setPanelRubroXFuente(PanelLayout pl) {
        this.panelRubroXFuente = pl;
    }
    private HtmlPanelGrid panelPrincipal = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelPrincipal() {
        return panelPrincipal;
    }

    public void setPanelPrincipal(HtmlPanelGrid hpg) {
        this.panelPrincipal = hpg;
    }
    private HtmlPanelGrid panelMensajes = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelMensajes() {
        return panelMensajes;
    }

    public void setPanelMensajes(HtmlPanelGrid hpg) {
        this.panelMensajes = hpg;
    }
    private HtmlMessages messageList = new HtmlMessages();

    public HtmlMessages getMessageList() {
        return messageList;
    }

    public void setMessageList(HtmlMessages hm) {
        this.messageList = hm;
    }
    private HtmlPanelGrid panelBuscar = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelBuscar() {
        return panelBuscar;
    }

    public void setPanelBuscar(HtmlPanelGrid hpg) {
        this.panelBuscar = hpg;
    }
    private HtmlPanelGrid panelTabla = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelTabla() {
        return panelTabla;
    }

    public void setPanelTabla(HtmlPanelGrid hpg) {
        this.panelTabla = hpg;
    }
    private HtmlPanelGrid panelBoton = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelBoton() {
        return panelBoton;
    }

    public void setPanelBoton(HtmlPanelGrid hpg) {
        this.panelBoton = hpg;
    }
    private HtmlPanelGrid p1 = new HtmlPanelGrid();

    public HtmlPanelGrid getP1() {
        return p1;
    }

    public void setP1(HtmlPanelGrid hpg) {
        this.p1 = hpg;
    }
    private HtmlCommandButton botonGuardar = new HtmlCommandButton();

    public HtmlCommandButton getBotonGuardar() {
        return botonGuardar;
    }

    public void setBotonGuardar(HtmlCommandButton hcb) {
        this.botonGuardar = hcb;
    }
    private HtmlCommandButton botonGuardar2 = new HtmlCommandButton();

    public HtmlCommandButton getBotonGuardar2() {
        return botonGuardar2;
    }

    public void setBotonGuardar2(HtmlCommandButton hcb) {
        this.botonGuardar2 = hcb;
    }
    private HtmlPanelGrid p2 = new HtmlPanelGrid();

    public HtmlPanelGrid getP2() {
        return p2;
    }

    public void setP2(HtmlPanelGrid hpg) {
        this.p2 = hpg;
    }
    private HtmlCommandButton botonCancelar = new HtmlCommandButton();

    public HtmlCommandButton getBotonCancelar() {
        return botonCancelar;
    }

    public void setBotonCancelar(HtmlCommandButton hcb) {
        this.botonCancelar = hcb;
    }
    private Tab tabEstPresupuesto2 = new Tab();

    public Tab getTabEstPresupuesto2() {
        return tabEstPresupuesto2;
    }

    public void setTabEstPresupuesto2(Tab t) {
        this.tabEstPresupuesto2 = t;
    }
    private PanelLayout panelRubroXTiempo = new PanelLayout();

    public PanelLayout getPanelRubroXTiempo() {
        return panelRubroXTiempo;
    }

    public void setPanelRubroXTiempo(PanelLayout pl) {
        this.panelRubroXTiempo = pl;
    }
    private HtmlPanelGrid panelPrincipal2 = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelPrincipal2() {
        return panelPrincipal2;
    }

    public void setPanelPrincipal2(HtmlPanelGrid hpg) {
        this.panelPrincipal2 = hpg;
    }
    private HtmlPanelGrid panelMensajes2 = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelMensajes2() {
        return panelMensajes2;
    }

    public void setPanelMensajes2(HtmlPanelGrid hpg) {
        this.panelMensajes2 = hpg;
    }
    private HtmlMessages messageList2 = new HtmlMessages();

    public HtmlMessages getMessageList2() {
        return messageList2;
    }

    public void setMessageList2(HtmlMessages hm) {
        this.messageList2 = hm;
    }
    private HtmlPanelGrid panelTabla2 = new HtmlPanelGrid();

    public HtmlPanelGrid getPanelTabla2() {
        return panelTabla2;
    }

    public void setPanelTabla2(HtmlPanelGrid hpg) {
        this.panelTabla2 = hpg;
    }
    private Table tableRubroXTiempo = new Table();

    public Table getTableRubroXTiempo() {
        return tableRubroXTiempo;
    }

    public void setTableRubroXTiempo(Table t) {
        this.tableRubroXTiempo = t;
    }
    private HtmlOutputText outputText = new HtmlOutputText();

    public HtmlOutputText getOutputText() {
        return outputText;
    }

    public void setOutputText(HtmlOutputText hot) {
        this.outputText = hot;
    }
    private HtmlSelectOneListbox listboxProyectoInvestigacion = new HtmlSelectOneListbox();

    public HtmlSelectOneListbox getListboxProyectoInvestigacion() {
        long idProyecto;
        String nombreProyecto;
        listboxProyectoInvestigacion = new HtmlSelectOneListbox();
        PresupuestosBO presupuestosBO = new PresupuestosBO();
        List<ProyectoInvestigacionVO> listaProyecto = new ArrayList<ProyectoInvestigacionVO>();
        List collection = new ArrayList();
        collection.add(new SelectItem(0, "-Seleccione un proyecto de Investigacion-"));
        try {
            listaProyecto = presupuestosBO.listarProyectos_conRubros();

            for (int i = 0; i < listaProyecto.size(); i++) {
                idProyecto = listaProyecto.get(i).getIdProyecto();
                nombreProyecto = listaProyecto.get(i).getTituloProyecto();

                collection.add(new SelectItem(idProyecto, nombreProyecto));
            }
            UISelectItems listaMenu = new UISelectItems();
            listaMenu.setValue(collection);
            listboxProyectoInvestigacion.getChildren().add(listaMenu);
        } catch (Exception e) {
            e.getStackTrace();
        }
        return listboxProyectoInvestigacion;
    }

    public void setListboxProyectoInvestigacion(HtmlSelectOneListbox hsol) {
        this.listboxProyectoInvestigacion = hsol;
    }
    private StaticText staticText5 = new StaticText();

    public StaticText getStaticText5() {
        return staticText5;
    }

    public void setStaticText5(StaticText st) {
        this.staticText5 = st;
    }
    private Table table1 = new Table();

    public Table getTable1() {
        return table1;
    }

    public void setTable1(Table t) {
        this.table1 = t;
    }
    private TableRowGroup tableRowGroup1 = new TableRowGroup();

    public TableRowGroup getTableRowGroup1() {
        return tableRowGroup1;
    }

    public void setTableRowGroup1(TableRowGroup trg) {
        this.tableRowGroup1 = trg;
    }
    private StaticText staticText2 = new StaticText();

    public StaticText getStaticText2() {
        return staticText2;
    }

    public void setStaticText2(StaticText st) {
        this.staticText2 = st;
    }
    private TableColumn tableColumn3 = new TableColumn();

    public TableColumn getTableColumn3() {
        return tableColumn3;
    }

    public void setTableColumn3(TableColumn tc) {
        this.tableColumn3 = tc;
    }
    private Table tableRubroXFuentes = new Table();

    public Table getTableRubroXFuentes() {
        return tableRubroXFuentes;
    }

    public void setTableRubroXFuentes(Table t) {
        this.tableRubroXFuentes = t;
    }
    private TableRowGroup tableRowGroup3 = new TableRowGroup();

    public TableRowGroup getTableRowGroup3() {
        return tableRowGroup3;
    }

    public void setTableRowGroup3(TableRowGroup trg) {
        this.tableRowGroup3 = trg;
    }
    private TableColumn tableColumn1 = new TableColumn();

    public TableColumn getTableColumn1() {
        return tableColumn1;
    }

    public void setTableColumn1(TableColumn tc) {
        this.tableColumn1 = tc;
    }
    private StaticText staticText1 = new StaticText();

    public StaticText getStaticText1() {
        return staticText1;
    }

    public void setStaticText1(StaticText st) {
        this.staticText1 = st;
    }
    private TableColumn tableColumn2 = new TableColumn();

    public TableColumn getTableColumn2() {
        return tableColumn2;
    }

    public void setTableColumn2(TableColumn tc) {
        this.tableColumn2 = tc;
    }
    private TableColumn tableColumn11 = new TableColumn();

    public TableColumn getTableColumn11() {
        return tableColumn11;
    }

    public void setTableColumn11(TableColumn tc) {
        this.tableColumn11 = tc;
    }
    private StaticText staticTextTotal = new StaticText();

    public StaticText getStaticTextTotal() {
        return staticTextTotal;
    }

    public void setStaticTextTotal(StaticText st) {
        this.staticTextTotal = st;
    }
    private Table tablaInterna = new Table();

    public Table getTablaInterna() {
        return tablaInterna;
    }

    public void setTablaInterna(Table t) {
        this.tablaInterna = t;
    }
    private TableRowGroup tableRowGroup4 = new TableRowGroup();

    public TableRowGroup getTableRowGroup4() {
        return tableRowGroup4;
    }

    public void setTableRowGroup4(TableRowGroup trg) {
        this.tableRowGroup4 = trg;
    }
    private TableColumn tableColumn4 = new TableColumn();

    public TableColumn getTableColumn4() {
        return tableColumn4;
    }

    public void setTableColumn4(TableColumn tc) {
        this.tableColumn4 = tc;
    }
    private StaticText staticText7 = new StaticText();

    public StaticText getStaticText7() {
        return staticText7;
    }

    public void setStaticText7(StaticText st) {
        this.staticText7 = st;
    }
    private TableColumn tableColumn5 = new TableColumn();

    public TableColumn getTableColumn5() {
        return tableColumn5;
    }

    public void setTableColumn5(TableColumn tc) {
        this.tableColumn5 = tc;
    }
    private TableColumn tableColumn12 = new TableColumn();

    public TableColumn getTableColumn12() {
        return tableColumn12;
    }

    public void setTableColumn12(TableColumn tc) {
        this.tableColumn12 = tc;
    }
    private StaticText staticText8 = new StaticText();

    public StaticText getStaticText8() {
        return staticText8;
    }

    public void setStaticText8(StaticText st) {
        this.staticText8 = st;
    }
    private TableColumn tableColumn13 = new TableColumn();

    public TableColumn getTableColumn13() {
        return tableColumn13;
    }

    public void setTableColumn13(TableColumn tc) {
        this.tableColumn13 = tc;
    }
    private StaticText staticText9 = new StaticText();

    public StaticText getStaticText9() {
        return staticText9;
    }

    public void setStaticText9(StaticText st) {
        this.staticText9 = st;
    }
    private TableColumn tableColumn14 = new TableColumn();

    public TableColumn getTableColumn14() {
        return tableColumn14;
    }

    public void setTableColumn14(TableColumn tc) {
        this.tableColumn14 = tc;
    }
    private StaticText staticText11 = new StaticText();

    public StaticText getStaticText11() {
        return staticText11;
    }

    public void setStaticText11(StaticText st) {
        this.staticText11 = st;
    }
    private Button buttonAsignarValores = new Button();

    public Button getButtonAsignarValores() {
        return buttonAsignarValores;
    }

    public void setButtonAsignarValores(Button b) {
        this.buttonAsignarValores = b;
    }
    private HtmlPanelGrid gridPanelEdicion = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanelEdicion() {
        return gridPanelEdicion;
    }

    public void setGridPanelEdicion(HtmlPanelGrid hpg) {
        this.gridPanelEdicion = hpg;
    }
    private StaticText staticText10 = new StaticText();

    public StaticText getStaticText10() {
        return staticText10;
    }

    public void setStaticText10(StaticText st) {
        this.staticText10 = st;
    }
    private StaticText staticText12 = new StaticText();

    public StaticText getStaticText12() {
        return staticText12;
    }

    public void setStaticText12(StaticText st) {
        this.staticText12 = st;
    }
    private HtmlPanelGrid gridPanel2 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel2() {
        return gridPanel2;
    }

    public void setGridPanel2(HtmlPanelGrid hpg) {
        this.gridPanel2 = hpg;
    }
    private HtmlPanelGrid gridPanel3 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel3() {
        return gridPanel3;
    }

    public void setGridPanel3(HtmlPanelGrid hpg) {
        this.gridPanel3 = hpg;
    }
    private Table tablaEdicion = new Table();

    public Table getTablaEdicion() {
        return tablaEdicion;
    }

    public void setTablaEdicion(Table t) {
        this.tablaEdicion = t;
    }
    private TableRowGroup tableRowGroup5 = new TableRowGroup();

    public TableRowGroup getTableRowGroup5() {
        return tableRowGroup5;
    }

    public void setTableRowGroup5(TableRowGroup trg) {
        this.tableRowGroup5 = trg;
    }
    private TableColumn tableColumn15 = new TableColumn();

    public TableColumn getTableColumn15() {
        return tableColumn15;
    }

    public void setTableColumn15(TableColumn tc) {
        this.tableColumn15 = tc;
    }
    private StaticText staticText13 = new StaticText();

    public StaticText getStaticText13() {
        return staticText13;
    }

    public void setStaticText13(StaticText st) {
        this.staticText13 = st;
    }
    private TableColumn tableColumn16 = new TableColumn();

    public TableColumn getTableColumn16() {
        return tableColumn16;
    }

    public void setTableColumn16(TableColumn tc) {
        this.tableColumn16 = tc;
    }
    private StaticText staticText14 = new StaticText();

    public StaticText getStaticText14() {
        return staticText14;
    }

    public void setStaticText14(StaticText st) {
        this.staticText14 = st;
    }
    private TableColumn tableColumn17 = new TableColumn();

    public TableColumn getTableColumn17() {
        return tableColumn17;
    }

    public void setTableColumn17(TableColumn tc) {
        this.tableColumn17 = tc;
    }
    private HtmlCommandButton botonModificar = new HtmlCommandButton();

    public HtmlCommandButton getBotonModificar() {
        return botonModificar;
    }

    public void setBotonModificar(HtmlCommandButton hcb) {
        this.botonModificar = hcb;
    }
    private TextField textFieldValorF = new TextField();

    public TextField getTextFieldValorF() {
        return textFieldValorF;
    }

    public void setTextFieldValorF(TextField tf) {
        this.textFieldValorF = tf;
    }
    private HiddenField hiddenIDRubro = new HiddenField();

    public HiddenField getHiddenIDRubro() {
        return hiddenIDRubro;
    }

    public void setHiddenIDRubro(HiddenField hf) {
        this.hiddenIDRubro = hf;
    }
    private TableRowGroup tableRowGroup2 = new TableRowGroup();

    public TableRowGroup getTableRowGroup2() {
        return tableRowGroup2;
    }

    public void setTableRowGroup2(TableRowGroup trg) {
        this.tableRowGroup2 = trg;
    }
    private TableColumn tableColumn6 = new TableColumn();

    public TableColumn getTableColumn6() {
        return tableColumn6;
    }

    public void setTableColumn6(TableColumn tc) {
        this.tableColumn6 = tc;
    }
    private StaticText staticText3 = new StaticText();

    public StaticText getStaticText3() {
        return staticText3;
    }

    public void setStaticText3(StaticText st) {
        this.staticText3 = st;
    }
    private TableColumn tableColumn7 = new TableColumn();

    public TableColumn getTableColumn7() {
        return tableColumn7;
    }

    public void setTableColumn7(TableColumn tc) {
        this.tableColumn7 = tc;
    }
    private StaticText staticText4 = new StaticText();

    public StaticText getStaticText4() {
        return staticText4;
    }

    public void setStaticText4(StaticText st) {
        this.staticText4 = st;
    }
    private TableColumn tableColumn8 = new TableColumn();

    public TableColumn getTableColumn8() {
        return tableColumn8;
    }

    public void setTableColumn8(TableColumn tc) {
        this.tableColumn8 = tc;
    }
    private Table tablaInternaPeriodos = new Table();

    public Table getTablaInternaPeriodos() {
        return tablaInternaPeriodos;
    }

    public void setTablaInternaPeriodos(Table t) {
        this.tablaInternaPeriodos = t;
    }
    private TableRowGroup tableRowGroup6 = new TableRowGroup();

    public TableRowGroup getTableRowGroup6() {
        return tableRowGroup6;
    }

    public void setTableRowGroup6(TableRowGroup trg) {
        this.tableRowGroup6 = trg;
    }
    private TableColumn tableColumn9 = new TableColumn();

    public TableColumn getTableColumn9() {
        return tableColumn9;
    }

    public void setTableColumn9(TableColumn tc) {
        this.tableColumn9 = tc;
    }
    private StaticText staticText6 = new StaticText();

    public StaticText getStaticText6() {
        return staticText6;
    }

    public void setStaticText6(StaticText st) {
        this.staticText6 = st;
    }
    private TableColumn tableColumn10 = new TableColumn();

    public TableColumn getTableColumn10() {
        return tableColumn10;
    }

    public void setTableColumn10(TableColumn tc) {
        this.tableColumn10 = tc;
    }
    private StaticText staticText15 = new StaticText();

    public StaticText getStaticText15() {
        return staticText15;
    }

    public void setStaticText15(StaticText st) {
        this.staticText15 = st;
    }
    private TableColumn tableColumn18 = new TableColumn();

    public TableColumn getTableColumn18() {
        return tableColumn18;
    }

    public void setTableColumn18(TableColumn tc) {
        this.tableColumn18 = tc;
    }
    private TableColumn tableColumn19 = new TableColumn();

    public TableColumn getTableColumn19() {
        return tableColumn19;
    }

    public void setTableColumn19(TableColumn tc) {
        this.tableColumn19 = tc;
    }
    private StaticText staticTextTotal1 = new StaticText();

    public StaticText getStaticTextTotal1() {
        return staticTextTotal1;
    }

    public void setStaticTextTotal1(StaticText st) {
        this.staticTextTotal1 = st;
    }
    private TableColumn tableColumn20 = new TableColumn();

    public TableColumn getTableColumn20() {
        return tableColumn20;
    }

    public void setTableColumn20(TableColumn tc) {
        this.tableColumn20 = tc;
    }
    private Button buttonAsignarValoresPeriodo = new Button();

    public Button getButtonAsignarValoresPeriodo() {
        return buttonAsignarValoresPeriodo;
    }

    public void setButtonAsignarValoresPeriodo(Button b) {
        this.buttonAsignarValoresPeriodo = b;
    }
    private HtmlPanelGrid gridPanelEdicionP = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanelEdicionP() {
        return gridPanelEdicionP;
    }

    public void setGridPanelEdicionP(HtmlPanelGrid hpg) {
        this.gridPanelEdicionP = hpg;
    }
    private HtmlPanelGrid gridPanel4 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel4() {
        return gridPanel4;
    }

    public void setGridPanel4(HtmlPanelGrid hpg) {
        this.gridPanel4 = hpg;
    }
    private StaticText staticText16 = new StaticText();

    public StaticText getStaticText16() {
        return staticText16;
    }

    public void setStaticText16(StaticText st) {
        this.staticText16 = st;
    }
    private StaticText staticText17 = new StaticText();

    public StaticText getStaticText17() {
        return staticText17;
    }

    public void setStaticText17(StaticText st) {
        this.staticText17 = st;
    }
    private HiddenField hiddenIDRubro1 = new HiddenField();

    public HiddenField getHiddenIDRubro1() {
        return hiddenIDRubro1;
    }

    public void setHiddenIDRubro1(HiddenField hf) {
        this.hiddenIDRubro1 = hf;
    }
    private HtmlPanelGrid gridPanel5 = new HtmlPanelGrid();

    public HtmlPanelGrid getGridPanel5() {
        return gridPanel5;
    }

    public void setGridPanel5(HtmlPanelGrid hpg) {
        this.gridPanel5 = hpg;
    }
    private Table tablaEdicionP = new Table();

    public Table getTablaEdicionP() {
        return tablaEdicionP;
    }

    public void setTablaEdicionP(Table t) {
        this.tablaEdicionP = t;
    }
    private TableRowGroup tableRowGroup7 = new TableRowGroup();

    public TableRowGroup getTableRowGroup7() {
        return tableRowGroup7;
    }

    public void setTableRowGroup7(TableRowGroup trg) {
        this.tableRowGroup7 = trg;
    }
    private TableColumn tableColumn21 = new TableColumn();

    public TableColumn getTableColumn21() {
        return tableColumn21;
    }

    public void setTableColumn21(TableColumn tc) {
        this.tableColumn21 = tc;
    }
    private StaticText staticText18 = new StaticText();

    public StaticText getStaticText18() {
        return staticText18;
    }

    public void setStaticText18(StaticText st) {
        this.staticText18 = st;
    }
    private TableColumn tableColumn23 = new TableColumn();

    public TableColumn getTableColumn23() {
        return tableColumn23;
    }

    public void setTableColumn23(TableColumn tc) {
        this.tableColumn23 = tc;
    }
    private TextField textFieldValorP = new TextField();

    public TextField getTextFieldValorP() {
        return textFieldValorP;
    }

    public void setTextFieldValorP(TextField tf) {
        this.textFieldValorP = tf;
    }
    private HtmlCommandButton botonModificarPeriodos = new HtmlCommandButton();

    public HtmlCommandButton getBotonModificarPeriodos() {
        return botonModificarPeriodos;
    }

    public void setBotonModificarPeriodos(HtmlCommandButton hcb) {
        this.botonModificarPeriodos = hcb;
    }
    private StaticText staticText19 = new StaticText();

    public StaticText getStaticText19() {
        return staticText19;
    }

    public void setStaticText19(StaticText st) {
        this.staticText19 = st;
    }
    private StaticText staticText20 = new StaticText();

    public StaticText getStaticText20() {
        return staticText20;
    }

    public void setStaticText20(StaticText st) {
        this.staticText20 = st;
    }
    private StaticText staticText21 = new StaticText();

    public StaticText getStaticText21() {
        return staticText21;
    }

    public void setStaticText21(StaticText st) {
        this.staticText21 = st;
    }
    private DefaultOptionsList menu2DefaultOptions = new DefaultOptionsList();

    public DefaultOptionsList getMenu2DefaultOptions() {
        return menu2DefaultOptions;
    }

    public void setMenu2DefaultOptions(DefaultOptionsList dol) {
        this.menu2DefaultOptions = dol;
    }
    private DefaultTableDataProvider defaultTableDataProvider = new DefaultTableDataProvider();

    public DefaultTableDataProvider getDefaultTableDataProvider() {
        return defaultTableDataProvider;
    }

    public void setDefaultTableDataProvider(DefaultTableDataProvider dtdp) {
        this.defaultTableDataProvider = dtdp;
    }

    // </editor-fold>
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public PresupuestoEstimado() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here

        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("CrearGrupos Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
        }

    // </editor-fold>
    // Perform application initialization that must complete
    // *after* managed components are initialized
    // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }
    rubroProyectoVO rubroVO;
    PresupuestosBO rubroBO;

    public String buttonVerRubro_action() throws Exception {
        try {
            int idProyecto;

            idProyecto = Integer.parseInt((String) listboxProyectoInvestigacion.getValue());
            panelTabla.setRendered(true);

            listarRubroProy(idProyecto);
            return null;

        } catch (Exception ex) {
            error("Inserción no realizada");
            ex.getStackTrace();
        }

        return "ok";
    }

    public String listarRubroProy(int idProy) throws Exception {

        try {

            List<rubroProyectoVO> listaRubroProy = new ArrayList<rubroProyectoVO>();
            
            rubroVO = new rubroProyectoVO();
            rubroBO = new PresupuestosBO();

            listaRubroProy = new ArrayList<rubroProyectoVO>();

            rubroVO.setTempo(rubroBO.tempoEstProy(idProy));
            rubroVO.setTipo_tiempo(rubroBO.tipo_Tiempo_Est(idProy));
            listaRubroProy = rubroBO.listaRubroProyecto(idProy);
            
            agregarFuentes(idProy, listaRubroProy);
            agregarPeriodos(idProy, listaRubroProy, rubroVO);

            int tam = listaRubroProy.size();

            if (listaRubroProy.get(tam-1).getTotal()==0){
                tableColumn14.setRendered(true);
            }else {
                tableColumn14.setRendered(false);

            }

            getSessionBean1().addListaRubroProyecto(listaRubroProy);

        } catch (ControlException ce) {
            error("Error al consultar los Rubros.");
            ce.getStackTrace();
        }

        return "ok";
    }

    private void agregarFuentes(int idProy, List<rubroProyectoVO> listaRubroProy) throws Exception {
        try {
            int valorFF = 0;
            int totalF = 0;

            Iterator it = listaRubroProy.iterator();
            while (it.hasNext()) {
                rubroProyectoVO rubroLocal = new rubroProyectoVO();
                rubroLocal = (rubroProyectoVO) it.next();
                List<fuenteRubroVO> listaFuentesProy = rubroBO.listaFuentesProy(idProy);

                rubroLocal.setListaRubros(listaFuentesProy);
                Iterator ii = rubroLocal.getListaRubros().iterator();
                while (ii.hasNext()) {
                    fuenteRubroVO fuenteLocal = new fuenteRubroVO();
                    fuenteLocal = (fuenteRubroVO) ii.next();
                   // valorFF = rubroBO.valorFuenteEst(idProy, rubroLocal.getIdRubro(), fuenteLocal.getIdFuenteF());
                    totalF = totalF + valorFF;
                    fuenteLocal.setValorFuenteF(valorFF);
                    valorFF = 0;
                }
                rubroLocal.setTotal(totalF);
                totalF = 0;

            }


        } catch (ControlException ce) {
            error("Error Asignando las fuentes");
            ce.getStackTrace();
        }
    }
    static int periodoProy=0;
    
    private void agregarPeriodos(int idProy, List<rubroProyectoVO> listaRubroProy, rubroProyectoVO rubroVO) throws Exception {
        try {
            int valorFP = 0;
            int totalP = 0;
            Iterator it = listaRubroProy.iterator();
            periodoProy = rubroVO.getTempo();
            staticText21.setText(rubroVO.getTipo_tiempo());
            
            while (it.hasNext()) {
                rubroProyectoVO rubroLocal = new rubroProyectoVO();
                rubroLocal = (rubroProyectoVO) it.next();
                rubroLocal.setTempo(rubroVO.getTempo());
                rubroLocal.setTipo_tiempo(rubroVO.getTipo_tiempo());
                
                ArrayList<periodoRubroVO> listaPeriodosProy = new ArrayList<periodoRubroVO>();
                for (int i=1 ; i<=rubroLocal.getTempo(); i++){
                    periodoRubroVO periodoLocal = new periodoRubroVO();
//                    periodoLocal.setCantidad_Periodos(i);
                    periodoLocal.setValorPeriodo(0);
                    valorFP = rubroBO.valorPeriodoEst(idProy, rubroLocal.getIdRubro(), i);
                    periodoLocal.setValorPeriodo(valorFP);
                    totalP = totalP + valorFP;
                    listaPeriodosProy.add(periodoLocal);
                }
                
                rubroLocal.setListaPeriodos(listaPeriodosProy);
                totalP = 0;
            }
        } catch (ControlException ce) {
            error("Error Asignando las Tiempo");
            ce.getStackTrace();
        }
    }
    
    private static List<Integer> listaValoresF = new ArrayList<Integer>();
    private static List<Integer> listaIdFuenteF = new ArrayList<Integer>();

    public String tabEstPresupuesto2_action() {
        // TODO: Replace with your code
        return null;
    }
   public String tabEstPreRFuenConcep_action() {
        // TODO: Replace with your code
        return null;
    }
    public String buttonAsignarValores_action() throws Exception {

        try {

            int idProy;
            List<fuenteRubroVO> listaFuentesProy;
            rubroBO = new PresupuestosBO();
            idProy = Integer.parseInt((String) listboxProyectoInvestigacion.getValue());

            listaFuentesProy = rubroBO.listaFuentesProy(idProy);

            getSessionBean1().addListaFuentesProyecto(listaFuentesProy);

            String actu = "", idRubro;

            actu = (String) staticText1.getText();
            staticText12.setValue(actu);

            idRubro = staticText8.getValue().toString();

            gridPanelEdicion.setRendered(true);

            hiddenIDRubro.setValue(idRubro);

        } catch (Exception e) {
            e.getStackTrace();
        }

        return null;
    }

    presupuestosVO rubroXFuente;
    PresupuestosBO rubroXPresupuestosBO;

    public String botonModificar_action() throws Exception {

        try {
            int totales = 0;
            rubroXFuente = new presupuestosVO();
            rubroXPresupuestosBO = new PresupuestosBO();
            rubroXFuente.setIdProyecto(Integer.parseInt(listboxProyectoInvestigacion.getValue().toString()));
            rubroXFuente.setIdRubro(Integer.parseInt(hiddenIDRubro.getValue().toString()));

            String error = "";

            for (int k = 0; k < listaValoresF.size(); k++) {
                rubroXFuente.setIdFuenteF(listaIdFuenteF.get(k));
                rubroXFuente.setValorFuenteXRubro_EST(listaValoresF.get(k));
                totales = totales + listaValoresF.get(k);
               // error = rubroXPresupuestosBO.insertarRubroXP_Est(rubroXFuente);
                
            }
            if (error.equals("OK")) {
                    info("Se ha insertado con exito");
            }

            listarRubroProy(rubroXFuente.getIdProyecto());
            listaValoresF.clear();
            listaIdFuenteF.clear();
            gridPanelEdicion.setRendered(false);
            panelTabla.setRendered(true);
        } catch (Exception e) {
            e.getStackTrace();
            error("No se pudo Insertar");
        }
        return null;
    }

    public String buttonAsignarValoresPeriodo_action() throws Exception {

        try {

            int idProy;
            List<periodoRubroVO> listaPeriodosProy;
            rubroBO = new PresupuestosBO();
            idProy = Integer.parseInt((String) listboxProyectoInvestigacion.getValue());

            listaPeriodosProy = new ArrayList<periodoRubroVO>();

            for (int i = 1; i <= periodoProy; i++) {
                periodoRubroVO periodoLocal = new periodoRubroVO();
//                periodoLocal.setCantidad_Periodos(i);
                periodoLocal.setValorPeriodo(0);
                listaPeriodosProy.add(periodoLocal);
            }


            //getSessionBean1().addListaPeriodosProyecto(listaPeriodosProy);

            String actu = "", idRubro;

            actu = (String) staticText3.getText();
            staticText17.setValue(actu);

            idRubro = staticText4.getValue().toString();

            gridPanelEdicionP.setRendered(true);

            hiddenIDRubro1.setValue(idRubro);

        } catch (Exception e) {
            e.getStackTrace();
        }

        return null;
    }
    
    
    public String botonGuardar_action() {

        return null;
    }

    public void textFieldValorF_processValueChange(ValueChangeEvent event) throws Exception {

        try {

            int valor = Integer.parseInt(event.getNewValue().toString());
            int idF = Integer.parseInt(staticText14.getValue().toString());

            if (valor != 0) {
                listaValoresF.add(valor);
                listaIdFuenteF.add(idF);
            }
        } catch (Exception e) {
            e.getStackTrace();
            error("Por favor inserte valores numericos");
        }
    }

    public String tabEstPresupuesto_action() {
        // TODO: Replace with your code
        return null;
    }
    
    public void textFieldValorP_processValueChange(ValueChangeEvent event) throws Exception {

        try {

            int valor = Integer.parseInt(event.getNewValue().toString());
            int idP = Integer.parseInt(staticText18.getValue().toString());

            if (valor != 0) {
                listaValoresP.add(valor);
                listaIdFuenteP.add(idP);
            }
        } catch (Exception e) {
            e.getStackTrace();
            error("Por favor inserte valores numericos");
        }
    }

    private static List<Integer> listaValoresP = new ArrayList<Integer>();
    private static List<Integer> listaIdFuenteP = new ArrayList<Integer>();
    presupuestosVO rubroXPeriodo;
    PresupuestosBO rubroXPeriodoBO;
    
    public String botonModificarPeriodos_action() throws Exception {

        try {
            int totalesP = 0;
            rubroXPeriodo = new presupuestosVO();
            rubroXPeriodoBO = new PresupuestosBO();
            rubroXPeriodo.setIdProyecto(Integer.parseInt(listboxProyectoInvestigacion.getValue().toString()));
            rubroXPeriodo.setIdRubro(Integer.parseInt(hiddenIDRubro1.getValue().toString()));

            String error = "";

            for (int k = 0; k < listaValoresP.size(); k++) {
                rubroXPeriodo.setTempo(listaIdFuenteP.get(k));
                rubroXPeriodo.setValorPeriodoXRubro_EST(listaValoresP.get(k));
                totalesP = totalesP + listaValoresP.get(k);
                error = rubroXPeriodoBO.insertarRubroXPeriodo_Est(rubroXPeriodo);
            }

            if (error.equals("OK")) {
                    info("Se ha insertado con exito");
            }

            listarRubroProy(rubroXPeriodo.getIdProyecto());
            listaValoresP.clear();
            listaValoresP.clear();
            gridPanelEdicionP.setRendered(false);
            panelTabla2.setRendered(true);
        } catch (Exception e) {
            e.getStackTrace();
            error("No se pudo Insertar");
        }
        return null;
    }

    public void listboxProyectoInvestigacion_processValueChange(ValueChangeEvent vce) {


        System.out.println("Funciona Menu");
        UIParameter parametro = (UIParameter) vce.getComponent().findComponent("param1");
        String param1 = parametro.getValue().toString();
        System.out.println(param1);
        try {
            int idProyecto;

            idProyecto = Integer.parseInt((String) listboxProyectoInvestigacion.getValue());
            panelTabla.setRendered(true);

            listarRubroProy(idProyecto);


        } catch (Exception ex) {
            error("Inserción no realizada");
            ex.printStackTrace();
        }


    }
 
}